﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace NCEdu.Web.userBaseInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(id);
				}
			}
		}
			
	private void ShowInfo(int id)
	{
		NCEdu.BLL.userBaseInfo bll=new NCEdu.BLL.userBaseInfo();
		NCEdu.Model.userBaseInfo model=bll.GetModel(id);
		this.lblid.Text=model.id.ToString();
		this.txtstuNo.Text=model.stuNo;
		this.txtmicStuNo.Text=model.micStuNo;
		this.txtstuName.Text=model.stuName;
		this.chksex.Checked=model.sex;
		this.txtbirthday.Text=model.birthday.ToString();
		this.txtnativePlace.Text=model.nativePlace;
		this.txthomeTel.Text=model.homeTel;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtstuNo.Text.Trim().Length==0)
			{
				strErr+="stuNo不能为空！\\n";	
			}
			if(this.txtmicStuNo.Text.Trim().Length==0)
			{
				strErr+="micStuNo不能为空！\\n";	
			}
			if(this.txtstuName.Text.Trim().Length==0)
			{
				strErr+="stuName不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtbirthday.Text))
			{
				strErr+="birthday格式错误！\\n";	
			}
			if(this.txtnativePlace.Text.Trim().Length==0)
			{
				strErr+="nativePlace不能为空！\\n";	
			}
			if(this.txthomeTel.Text.Trim().Length==0)
			{
				strErr+="homeTel不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int id=int.Parse(this.lblid.Text);
			string stuNo=this.txtstuNo.Text;
			string micStuNo=this.txtmicStuNo.Text;
			string stuName=this.txtstuName.Text;
			bool sex=this.chksex.Checked;
			DateTime birthday=DateTime.Parse(this.txtbirthday.Text);
			string nativePlace=this.txtnativePlace.Text;
			string homeTel=this.txthomeTel.Text;


			NCEdu.Model.userBaseInfo model=new NCEdu.Model.userBaseInfo();
			model.id=id;
			model.stuNo=stuNo;
			model.micStuNo=micStuNo;
			model.stuName=stuName;
			model.sex=sex;
			model.birthday=birthday;
			model.nativePlace=nativePlace;
			model.homeTel=homeTel;

			NCEdu.BLL.userBaseInfo bll=new NCEdu.BLL.userBaseInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
